//***************************************************************
// led.h, led.c
// lightening led according to the beat
// ee_hqxaa, Hilda
//***************************************************************
//* we make use of DCT to get the basic frequency
// FS, sampling frequency is 100Hz, implement by timer interupt
// window is 16 samples, each of which is 8bit ADC output
//***************************************************************
// the signal is downsampled to 11.025Hz and convert to mono
// long window(0.0928s) for music without percussion
// short window(0.0464s)for music with percussion
// hop size: 0.0058s
//--------------onset energy
// simulate the attenuation of human middle ear // filter reinforcing the mid-range frequncy
// low-pass filtered (elliptic filter of order 5, fc = 10Hz)
// simple differentiated [1,-1]
// half-wave rectified
// sum over all frequency to get resulting energy en(t)
//--------------tempo estimate
// F(w,t) is spectrum of en(t)                    //hamming window 6s, hop 0.5s
// A(l,t) is auto-correlation of en(t)            // lag l ==> periodicity of w/samplerate
// F and A are two ways to describe energy centered at frequency w
// Y = F .* A
// so we can avoid both F's DFT's harmonics, avoid A's sub-harmonics



#ifndef __LED_H__
#define __LED_H__

#define IDLE		0
#define PLAY		1
#define MODE		PINC.0
//#define LEDPORT		PORTA

#define WINDOW		16
#define DEGREE  	4
#define threshold 	0



// define constant
#define uint8	unsigned char
#define uint16	unsigned int
#define uint32	unsigned long



// define pins
#define ADCDATA	PORTF
#define SOURCE  PINA.0
#define LED		PORTA
#define IDLE0	1
#define IDLE1   1

// function acclaim

// define external function
extern void LED_ini();
extern void sample(unsigned int *, unsigned char*);
extern void idlelight(unsigned char *);
extern void playlight(unsigned char *);
extern void offlight(void);
extern void calbeat(uint16 *data, uint8 *cnt);
extern void sample(uint16 * data, uint8 * index);

#endif

